#include "stdafx.h"
#include "Thread.h"

Thread::Thread(ThreadPriority p,string nme) : priority(p), name(nme)
{
}

Thread::~Thread()
{
	CloseHandle(hThread);
}


Thread::ThreadPriority Thread::getPriority()
{
	return priority;
}


std::string Thread::getName()
{
	return name;
}


bool Thread::setPriority(Thread::ThreadPriority p)
{
	return SetThreadPriority(hThread, p);
}

bool Thread::start()
{
	SetThreadPriority(hThread,priority);

	hThread = CreateThread(
                NULL,
                0,
				(LPTHREAD_START_ROUTINE) threadMapper,
                this,
                0,
                &this->threadId);
            if (hThread)
                return true;
            return false;
}


void* Thread::threadMapper(void* thread)
{
	((Thread*) thread)->run();
	return NULL;
}


SleepTimer::SleepTimer()
{

}

SleepTimer::~SleepTimer()
{

}


void SleepTimer::sleep(unsigned long ms)
{
	Sleep(ms);
}